package com.hsd.controller;

import com.hsd.entity.Account;
import com.hsd.service.IAccountService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/test")
public class TestController {
    @Resource
    IAccountService accountService;

    @RequestMapping("/acc/all")
    @ResponseBody
    public List<Account> findAll() {
        return accountService.findAll();
    }

    @RequestMapping("/acc/save")
    @ResponseBody
    public String save(String acc, Double money) {
        return accountService.save(acc, money) ? "save success" : "save fail";
    }

    @RequestMapping("/acc/take")
    @ResponseBody
    public String take(String acc, Double money) {
        return accountService.take(acc, money) ? "take success" : "take fail";
    }

    @RequestMapping("/acc/transfer")
    @ResponseBody
    public String transfer(String from, String to, Double money) {
        return accountService.transfer(from, to, money) ? "transfer success" : "transfer fail";
    }
}
